package com.example.androidclass;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {
    TextView calculate_textView;
    String calculate_info = "";
    String calculate_result = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        Button btn_calculator = (Button) findViewById(R.id.btn_calculator);
        Button btn_save_text = (Button) findViewById(R.id.save_text);
        Button btn_campus_network = (Button) findViewById(R.id.campus_network);
        Button btn_plan = (Button) findViewById(R.id.timeline);
        calculate_textView = findViewById(R.id.calculate_result);
        calculate_info = String.valueOf(calculate_textView.getText());

        btn_save_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SaveText.class);
                startActivity(intent);
            }
        });

        btn_calculator.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, Calculator.class);
                intent.putExtra("extra_data", calculate_result);
                startActivityForResult(intent,1);
            }
        });

        btn_campus_network.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, CampusNetwork.class);
                startActivity(intent);
            }
        });

        btn_plan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, Schedule.class);
                startActivity(intent);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    String returnedData = data.getStringExtra("data_return");
                    calculate_result = returnedData;
                    calculate_textView.setText(calculate_info + calculate_result);
                }
        }
    }
}
























